// Doc/Reference/Logging.md
#if !(UNITY_EDITOR || DEBUG)
#define AL_OPTIMIZE
#endif

#if !AL_OPTIMIZE

using static Active.Status;
using F = Active.Core.Details.StatusFormat;
using S = System.String;
using V = Active.Core.Details.ValidString;

namespace Active.Core.Details
{
    public static class Logging
    {

        internal static status Status(in status @base, V reason,
                                      S p, S m, int l)
        => log ? ViaScope(@base, F.SysTrace(p, m, l), reason) : @base;

        internal static action Action(V reason, S p, S m, int l) => log
        ? new action(ViaScope(status._done,
                              F.SysTrace(p, m, l), reason).meta)
        : action._done;

        internal static failure Failure(V reason, S p, S m, int l) => log
        ? new failure(ViaScope(status._fail,
                               F.SysTrace(p, m, l), reason).meta)
        : failure._fail;

        internal static loop Forever(V reason, S p, S m, int l) => log
        ? new loop(ViaScope(status._cont, F.SysTrace(p, m, l), reason).meta)
        : loop._cont;

        internal static pending Pending(pending @base, V reason,
                                        string p, string m, int l) => log
        ? new pending(@base.ω, ViaScope(@base.due,
                                        F.SysTrace(p, m, l), reason).meta)
        : @base;

        internal static impending Impending(impending @base, V reason,
                                            string p, string m, int l) => log
        ? new impending(@base.ω, ViaScope(@base.undue,
                                          F.SysTrace(p, m, l), reason).meta)
        : @base;

        internal static status ViaScope(in status s, object scope,
                                                     string reason)
        => new status(s.ω, s.meta.ViaScope(s, scope, reason));

    }
}  // Active.Core.Details

#endif  // !AL_OPTIMIZE
